package pATT.core.Chooser;

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class ImageFilter extends FileFilter {
	public final static String ARFF_EXTENSION = "arff";
	public final static String PROF_EXTENSION = "prof";
	public static final String XML_EXTENSION = "xml";
	public static final String PERSONAL_SEARCHER_EXTENSION = "psearcher";
	public static final String SAVER_EXTENSION = "xmlsaver";
	private String FILE_EXTENSION = "";
	
	
	
	public ImageFilter(String extension) {
		super();
		FILE_EXTENSION = extension;
	}


	public boolean accept(File f) {
		
		if (f.isDirectory()) {
			return true;
		}
		
		String s = f.getName();
		int i = s.lastIndexOf('.');
		
		if (i > 0 &&  i < s.length() - 1) {
			String extension = s.substring(i+1).toLowerCase();
			if (FILE_EXTENSION.equals(extension))
			{
				return true;
			} else {
				return false;
			}
		}
		
		return false;
	}
	
	
	public String getDescription() {
		return FILE_EXTENSION+" Files";
	}
	
	public boolean isArffFileValid(File file){
		boolean value = true;
		String pathFile = file.getPath();
		if(!file.exists() || !file.isFile())
			return false;		
		if(!pathFile.endsWith("."+ARFF_EXTENSION))
			return false;
		int pos = pathFile.indexOf(".");
		String temp = "";
		if(pos != -1)
		   temp = pathFile.substring(pos+1);
		System.out.println("temp: "+pos+"  "+temp);
		if(temp.indexOf(".") != -1)
			value = false;
		return value;
	}

	public boolean isFileValid(File file, String extension) {
		boolean value = true;
		String pathFile = file.getPath();
		if(!file.exists() || !file.isFile())
			return false;		
		if(!pathFile.endsWith("."+extension))
			return false;
		int pos = pathFile.indexOf(".");
		String temp = "";
		if(pos != -1)
		   temp = pathFile.substring(pos+1);
		System.out.println("temp: "+pos+"  "+temp);
		if(temp.indexOf(".") != -1)
			value = false;
		return value;
	}


	public boolean isXMLFileValid(File file) {
		boolean value = true;
		String pathFile = file.getPath();
		if(!file.exists() || !file.isFile())
			return false;		
		if(!pathFile.endsWith("."+XML_EXTENSION))
			return false;
		int pos = pathFile.indexOf(".");
		String temp = "";
		if(pos != -1)
		   temp = pathFile.substring(pos+1);
		System.out.println("temp: "+pos+"  "+temp);
		if(temp.indexOf(".") != -1)
			value = false;
		return value;
	}


}

